# Contributor:
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lua-bitop
pkgver=1.0.2
pkgrel=0
pkgdesc="Bitwise operations on numbers"
url="https://bitop.luajit.org/"
arch="all"
license="MIT"
source="https://bitop.luajit.org/download/LuaBitOp-$pkgver.tar.gz"
builddir="$srcdir/LuaBitOp-$pkgver"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make -C "$builddir-$lver" LUA="lua$lver"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	cd "$builddir-$lver"
	install -Dm 644 bit.so "$subpkgdir/usr/lib/lua/$lver/bit.so"
}

sha512sums="a652050ea5c6fbeb8a28b05e2bc4a3550c854cc45f7f42c8c1b0a81f5b76773cdf061e6a839cdb339614118169e578b6e3efa5a3efbe59a2f01874b2fa2b4f2e  LuaBitOp-1.0.2.tar.gz"
